#### date 2025-0314


proc pr_check_inst {} {
    puts "all insts number:"
    llength [dbget top.insts.isPhysOnly 0 -p]
}

proc pr_report_timing {} {
    set_global timing_report_enable_verbose_ssta_mode true
    set_global timing_report_enable_auto_column_width true
    set_global report_timing_format {hpin cell fanout load slew user_derate delay_mean delay_sigma delay arrival_mean arrival_sigma arrival edge instance_location } 
}


#### floorplan
if { 1 } {
    set path [pwd]
    source ${path}/flow/init.tcl
    source ${path}/flow/fp.tcl

    deleteRow -site ipcoreExt
    createRow -noFlip -site ipcoreExt -spacing -2.88 -noAbut
    clearDrc

    defIn ${path}/dataout/fp_ip_place.def.20250313
    
    source ${path}/flow/run_tcic.tcl
    source ${path}/scripts/add_pin.tcl
    source ${path}/scripts/add_blkage.tcl


    defIn ${path}/dataout/pdata_ndata.routing.250313
    pr_check_inst
    saveIoFile ./io.file

}

#### PG
if { 1 } {
    #selectInstByCellName DOUBLE_EDGE_FF
    selectInstByCellName DLY_LINE_512
    selectInstByCellName dll_fine
    pr_add_IP_PlaceBlkage
    deselectAll
    
    source ${path}/scripts/add_ENDCAP.tcl
    pr_addTAPCell

    globalNetConnect VDDC -type pgpin -pin VDD -all -override
    globalNetConnect VDDC -type pgpin -pin VPP -all -override
    globalNetConnect GNDC -type pgpin -pin VSS -all -override
    globalNetConnect GNDC -type pgpin -pin VBB -all -override

    selectInstByCellName DLY_LINE_512
    selectInstByCellName dll_fine
    pr_add_IP_RoutingBlkage
    deselectAll
    pr_add_PIN_RouteBlkage_pg
    pr_add_layoutRouting_RouteBlkage
    
    source ${path}/scripts/add_PG.tcl
    pr_add_M0
    pr_add_M1ToM3
    ## PG color
    colorizePowerMesh -reverse_with_nondefault_width 1

    pr_add_via_RouteBlkage
    pr_add_M4ToM10
    pr_del_via_RouteBlkage
    pr_add_PG_VIA
    pr_del_IP_RoutingBlkage
    pr_add_IP_VIA

    pr_check_inst

} 


#### place
if { 1 } {
    set path [pwd]
    set_dont_touch [get_cells -hierarchical *]
    set_dont_touch [get_nets -hierarchical *]
    
    setDesignMode -topRoutingLayer "M11"
    place_design
    optDesign -preCTS

    pr_report_timing
    timeDesign -preCTS -prefix place -outDir "./timeReport"

    pr_check_inst
}

#### CTS
if { 1 } {
    source ./flow/ccopt.tcl
    optDesign -postCTS

    pr_report_timing
    timeDesign -postCTS -prefix CTS -outDir "./timeReport"

    pr_check_inst
}

#### route
if { 1 } {
    source ${path}/scripts/add_NDR.tcl
    pr_clk_ndr

    pr_del_PIN_RouteBlkage_pg
    pr_add_PIN_RouteBlkage_route

    routeDesign
    optDesign -postRoute

    pr_report_timing
    timeDesign -postRoute -prefix route -outDir "./timeReport"

    pr_check_inst
}

#### fix short

verifyConnectivity
ecoRoute -fix_drc


#### output
source ${path}/scripts/get_hcell.tcl
source ${path}/flow/stream.tcl